$(function(){
	/**
	 * 查询所属角色的权限并填入
	 */
	var roleId = $.trim($("#roleId").text());//得到角色 
	var url_queryPermissionByRoleId = 'oa-role/tbPermissionAction_queryPermissionByRoleId.action';
	var req_queryPermissionByRoleId = {'tbRole.tbRoleId':roleId};
	$.post(url_queryPermissionByRoleId,req_queryPermissionByRoleId,function(data){
		$.each(data.tbPermissionList,function(i,object){
			
			if($("#" + object.PId+"").children('ul').children().length==0){	//叶子
				$("#" + object.PId+"").children('.checkbox').click();
			}
		});
	});
	
	/**
	 * 取得所有的勾
	 */
	$(".submit").click(function(){
		var permissionIdString='';
		$.each($("div.checked").parent(),function(i,object){
//			alert($(object).attr('id'));
			permissionIdString +=$(object).attr('id');
			permissionIdString +=',';
		});
		
		$.each($("div.half_checked").parent(),function(i,object){
//			alert($(object).attr('id'));
			permissionIdString +=$(object).attr('id');
			permissionIdString +=',';
		});
		
		var url_submitRolePermissionList="oa-role/tbPermissionAction_submitRolePermissionList.action";
		var req_submitRolePermissionList={
				'tbRole.tbRoleId':roleId,
				'permissionIdString':permissionIdString
		};
		
		$.post(url_submitRolePermissionList,req_submitRolePermissionList,function(data){
				alert(data.message);
		});
		
	});
	
	$("#return").click(function(){
		window.history.go(-1);
	});
	
});